//
//  XFSymptomViewController.m
//  名医通
//
//  Created by zyc on 16/7/12.
//  Copyright © 2016年 mr.zhou. All rights reserved.
//

#import "XFSymptomViewController.h"

#define symptomIndentifier @"symptomIndentifier"

@interface XFSymptomViewController ()<UITableViewDataSource,UITableViewDelegate>
/**
 *  疾病症状的数组
 */
@property (nonatomic,strong) NSArray *symptomArray;

@property (nonatomic,strong) UITableView *tableView;

@property (nonatomic,strong) NSMutableArray *selectedSymptom;

@end

@implementation XFSymptomViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    
    [self.view addSubview:self.tableView];
    
    self.tableView.delegate = self;
    
    self.tableView.dataSource = self;
    
    self.tableView.scrollEnabled = NO;


}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.symptomArray.count;

}

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:symptomIndentifier];
    if (cell == nil) {
    
        cell = [[UITableViewCell  alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:symptomIndentifier];
    }
    
    cell.textLabel.text = self.symptomArray[indexPath.row];
    /**
     右侧的选择对号button
     */
    UIButton *button = [[UIButton alloc] initWithFrame:(CGRectMake(0, 0, 20, 20))];
    
    [button setImage:[UIImage imageNamed:@"duihao"] forState:(UIControlStateSelected)];
    
    [button setImage:[UIImage imageNamed:@"duihaobai"] forState:(UIControlStateNormal)];
    
    cell.accessoryView = button;
    
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    
    UIButton *button =  (UIButton *)cell.accessoryView;
    
    button.selected = !button.selected;
    
    if (button.selected) {
    
        [self.selectedSymptom addObject:self.symptomArray[indexPath.row]];
    
    } else {
    
        [self.selectedSymptom removeObject:self.symptomArray[indexPath.row]];
    
    }
    
    self.didSelectedSymptoms(self.selectedSymptom);
    
    
}

#pragma mark - 懒加载

-(NSArray *)symptomArray {
    if (_symptomArray == nil) {
        _symptomArray = [NSArray arrayWithObjects:@"腹痛",@"厌食",@"乏力",@"体重减轻",@"恶心",@"呕吐",@"呕血", nil];
    }
    return _symptomArray;
}

-(NSMutableArray *)selectedSymptom {

    if (_selectedSymptom == nil) {
        _selectedSymptom = [NSMutableArray array];
    }
    return _selectedSymptom;
}


@end
